import * as echarts from "echarts";

import {size} from "lodash";


const screen_w = window.innerWidth;

const font_size = 16


/**
 * @description: 生成ec图表配置信息
 * @author: 王琛
 * @Date: 2022-11-25 15:29:43
 * @param {*}
 * @return {*}
 */
export const analogData = {
    pie_size: 40,
    pie_position: ["center", "40%"],
    data: [35, 30],
    label: ['>100000', '50000-1000'],
    color_list: ['0,132,255', '55,255,201', '25,214,255', '255,231,119']
}

export function getOptions({
                               pie_size = 45,
                               pie_position = ["center", "40%"],
                               data = [35, 30],
                               label = ['>100000', '50000-1000'],
                               color_list = ['0,132,255', '55,255,201', '25,214,255', '255,231,119', '0,132,255', '55,255,201', '25,214,255', '255,231,119', '0,132,255', '55,255,201', '25,214,255', '255,231,119'],
                               labelFormatter = null,
                               legend={ type:'' }
                           } = {}) {
    // 总数保存变量
    let total = 0;
    // 数据名称
    let getsjjg = label;
    let getsjjgrs = data;
    // 最终的展示数据
    let syjgdata = [];
    let syjgdata_no_name = [];
    // 计算总数
    for (let i in getsjjgrs) {
        total += getsjjgrs[i];
    }
    // 数据整合
    for (var i = 0; i < getsjjg.length; i++) {
        syjgdata_no_name.push(
            {
                // name: getsjjg[i],
                value: Number(getsjjgrs[i]).toFixed(0),
            },
            {
                value: total / 150,
                name: '',
            }
        )
        syjgdata.push(
            {
                name: getsjjg[i],
                value: Number(getsjjgrs[i]).toFixed(0),
            },
            {
                value: total / 150,
                name: '',
            }
        );
    }


    // 数据颜色
    let colorList = []

    for (let i = 0, len = color_list.length; i < len; i++) {

        const color_list_item = color_list[i];

        colorList.push(...[[`rgba(${color_list_item},1)`, `rgba(${color_list_item},0.3)`], ['', '']])

    }

    let options = {
        tooltip: {
            trigger: 'item',
            textStyle: {
                fontSize: font_size
            }
            // formatter: (config) => {
            // 	console.log('%c日志-150708', 'color:#fff;fontSize:15px;background:#993366;padding:2px 5px;border-radius:6px', config);
            // 	return ""
            // }
        },
        legend: {
            icon: 'rect',
            itemWidth: font_size - 5,
            itemHeight: font_size - 5,
            bottom: '0',
            type: legend.type,
            textStyle: {
                color: '#D7E5FF',
                fontSize: font_size
            },
            formatter: (name) => {

                const labelIndex = label.findIndex(e => e == name);

                return !name ? "" : `${name} ${data[labelIndex]} 台`
            }
        },
        series: [
            {
                itemStyle: {
                    normal: {
                        color: 'rgba(0,0,0,0.3)',
                    },
                },
                type: 'pie',
                hoverAnimation: false,
                radius: [`${pie_size}%`, `${pie_size + 10}%`],
                center: pie_position,
                label: {
                    normal: {
                        show: false,
                    },
                },
                data: [
                    {
                        value: 1,
                    },
                ],
                z: 100,
            },
            {
                itemStyle: {
                    normal: {
                        color: 'rgba(0,0,0,0.3)',
                    },
                },
                type: 'pie',
                hoverAnimation: false,
                radius: [`${pie_size}%`, `${pie_size + 20}%`],
                center: pie_position,
                label: {
                    normal: {
                        show: false,
                    },
                },
                data: [
                    {
                        value: 1,
                    },
                ],
                z: 100,
            },
            {
                itemStyle: {
                    color: function (params) {
                        if (params.dataIndex == 0) {

                            return colorList[params.dataIndex][0]
                        } else {
                            if (params.dataIndex % 2 == 0) {

                                return colorList[params.dataIndex][0]
                            }
                        }
                    },
                },
                labelLine: {
                    show: true,
                    length: 10,
                    length2: 10,
                    lineStyle: {
                        width: 1,
                    }
                },
                label: {
                    show: true,
                    color: '#fff',
                    fontSize: font_size,
                    formatter: (params) => {
                        if (labelFormatter) {
                            return labelFormatter(params);
                        } else {
                            const _val = params.name ? params.value : "";

                            return _val ? `${_val}台` : '';
                        }
                    }
                },
                hoverAnimation: true,
                type: 'pie',
                radius: [`${pie_size}%`, `${pie_size + 30}%`],
                center: pie_position,
                data: syjgdata,
                z: 1,
            },
        ]
    };
    return options;
}

/**
 * @description: 获取当前折线图的 series 对象
 * @author: 王琛
 * @Date: 2022-11-25 16:18:34
 * @param {*}
 * @return {*}
 */


